﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using MS.InformationManagement.Presenter.UserManagement;
using MS.InformationManagement.DAL.DocumentCenter;
using System.Collections.Generic;
using MS.InformationManagement.Support;
using MS.InformationManagement.Support.Constants;

namespace MS.InformationManagement.WP.Layouts.MS.InformationManagement.WP
{
    public partial class UsersManagement : LayoutsPageBase, IUserManagementView
    {

        #region fields

        UserManagementPresenter _presenter;
        Dictionary<string, object> _properties;

        #endregion

        #region Properties

        public IEnumerable<UsuarioSistema> SystemUsers { get; set; }

        public SPFieldUserValueCollection SelectedUsers
        {
            get
            {
                return PeopleHelper.GetUsersFromPeopleEditor(PeopleEditorDestinatario);
            }
        }

        public Dictionary<string, object> Properties
        {
            get
            {
                _properties = getProperties();
                return _properties;
            }
            set
            {
                _properties = value;
            }
        }


        #endregion

        #region form events

        protected void Page_Load(object sender, EventArgs e)
        {
            _presenter = new UserManagementPresenter(this);
            if (IsPostBack) return;
            _presenter.HandleLoad();
        }

        protected void CreateUsers(object sender, EventArgs e)
        {
            _presenter.CreateUsers();
        }

        #endregion

        #region Implemented Methods

        public void Show()
        {
            rptExistingUsers.DataSource = SystemUsers;
            rptExistingUsers.DataBind();
        }

        public new event Presenter.Support.Events.ErrorHandler OnError;

        public event Presenter.Support.Events.SuccessHandler OnSuccess;

        #endregion


        #region Private Methods

        private Dictionary<string,object> getProperties()
        {
            Dictionary<string, object> properties = new Dictionary<string, object>();
            properties.Add(GlobalConstants.UP_DEPARTMENT, ddlDeptos.SeletedTerm);            
            return properties;
        }

        #endregion

    }
}
